package at.fhj.itm11.forum.beans;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import at.fhj.itm11.forum.model.Topic;
import at.fhj.itm11.forum.util.ForumConstants;


@ManagedBean
@RequestScoped
public class TopicBean {

	private ExternalContext externalContext;
	private HttpSession session;
	
	/*
	 * Constructor Method
	 */
	@PostConstruct
	public void init() {
		externalContext = FacesContext.getCurrentInstance().getExternalContext();
		session = (HttpSession) externalContext.getSession(true);
	}
	
	public Topic getCurrentTopic() {
		return (Topic) session.getAttribute(ForumConstants.SESSION_CURRENT_TOPIC);
	}

	public void setCurrentTopic(Topic currentTopic) {
		if (currentTopic == null) {
			throw new IllegalArgumentException();
		}
		session.setAttribute(ForumConstants.SESSION_CURRENT_TOPIC, currentTopic);
	}	
}